<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.user.php');
$admin=new admin();

$n=array(


array('label'=>'Site Settings',
	  'href'=>'/admin/resources/php/requests/forms/site-settings.php',
	  'order'=>intval(0),	
	  'is_parent'=>intval(1),
	  'parent'=>'',
	  'id'=>'list-site-settings',
	  'active'=>intval(1)
	  ),
array('label'=>'Pages / Content',
	  'href'=>'/admin/resources/php/requests/lists/pages.php',
	  'order'=>intval(1),	
	  'is_parent'=>intval(1),
	  'parent'=>'',
	  'id'=>'list-pages',
	  'active'=>intval(1)
	  ),
array('label'=>'Modules',
	  'href'=>'/admin/resources/php/requests/forms/modules.php',
	  'order'=>intval(2),	
	  'is_parent'=>intval(1),
	  'parent'=>'',
	  'id'=>'modules-click',
	  'active'=>intval(1)
	  ),
array('label'=>'Forms',
	  'href'=>'/admin/resources/php/requests/forms/forms.php',
	  'order'=>intval(3),	
	  'is_parent'=>intval(1),
	  'parent'=>'',
	  'id'=>'forms-click',
	  'active'=>intval(1)
	  ),
array('label'=>'Blog Posts',
	  'href'=>'/admin/resources/php/requests/forms/blog-posts.php',
	  'order'=>intval(4),	
	  'is_parent'=>intval(1),
	  'parent'=>'',
	  'id'=>'blogs-click',
	  'active'=>intval(1)
	  ),
array('label'=>'Groups &amp; Access',
	  'href'=>'/admin/resources/php/requests/forms/add-group.php',
	  'order'=>intval(4),	
	  'is_parent'=>intval(1),
	  'parent'=>'',
	  'id'=>'blogs-click',
	  'active'=>intval(1)
	  )
);
$data=new database();
$data->db(DATABASE)->collection('admin_navigation');

//echo('<pre>');
foreach($n as $k=>$v) {
$data->criteria($v)->insert();
}
$data->close();
$data=new database();
$data->db(DATABASE)->collection('admin_navigation');
$data->criteria(array('label'=>1))->uniqueIndex();
$data->close();
$data=new database();
$data->db(DATABASE)->collection('admin_navigation');
$data->criteria(array('href'=>1))->uniqueIndex();
$data->close();

function getModulesNav() {
$data=new database();
$data->db(DATABASE)->collection('admin_navigation');
$data->criteria(array('label'=>'Modules'));
$row=$data->findOne();
$data->close();
return $row;	
}
$data=new database();
$data->db(DATABASE)->collection('admin_navigation');
$m=getModulesNav();
$modules=$admin->getActiveModules();
foreach($modules['results'] as $row) {
	$item=array('label'=>$row['name'].' (module)',
	  'href'=>'/modules/'.$row['path'].'/admin/index.php',
	  'order'=>intval(1),	
	  'is_parent'=>intval(0),
	  'parent'=>(string)$m['_id'],
	  'id'=>'sub-'.$row['path'].'-click',
	  'active'=>intval(1)
	  );
$data->criteria($item)->insert();
}
$data->close();
?>